
/*jslint node: true */
/*global define, doh */
'use strict';

var version = require(global.voloLib + '/version'),
    q = require('q'),
    start = q.defer(),
    end;

function validate(t, expected, actual) {
    var i;

    t.is(expected.length, actual.length);

    for (i = 0; i < expected.length; i += 1) {
        t.is(expected[i], actual[i]);
    }
}

end = start.promise.then(function () {
    doh.register("versionTests",
        [
            function versionTests(t) {
                var list1 = ['0.2.0', '0.2.1', '0.3.1', '0.3.0', '1.3.1beta1', '1.3.1pre1', '1.3.1pre2', '1.2.0', '1.3.1'],
                    expected1 = ['1.3.1', '1.3.1pre2', '1.3.1pre1', '1.3.1beta1', '1.2.0', '0.3.1', '0.3.0', '0.2.1', '0.2.0'],
                    list2 = [ 'v2.5.0',
                      'v1.15.1',
                      'v2.10.3',
                      'v2.1.1',
                      'v2.10.0',
                      'v2.8.1',
                      'v1.2.0',
                      'v1.23.0',
                      'v2.4.5',
                      'v1.9.0',
                      'v1.5.1',
                      'v1.8.5',
                      'v2.4.2',
                      'v1.29.5',
                      'v2.7.3',
                      'v1.8.2',
                      'v1.29.2',
                      'v2.0.3',
                      'v1.14.0',
                      'v1.10.1',
                      'v2.7.0',
                      'v2.3.4',
                      'v2.0.0',
                      'v2.3.1',
                      'v1.17.1',
                      'v1.25.0',
                      'v1.13.2',
                      'v1.4.0',
                      'v1.28.1',
                      'v1.0.1',
                      'v1.16.0',
                      'v2.9.6',
                      'v2.9.3',
                      'v1.20.3',
                      'v2.2.0',
                      'v2.9.0',
                      'v1.19.1',
                      'v1.20.0',
                      'v2.5.1',
                      'v1.6.0',
                      'v1.27.0',
                      'v1.2.1',
                      'v2.1.2',
                      'v2.10.1',
                      'v2.4.6',
                      'v1.9.1',
                      'v1.11.0',
                      'v1.18.0',
                      'v2.4.3',
                      'v1.29.6',
                      'v1.5.2',
                      'v1.14.1',
                      'v2.4.0',
                      'v1.8.3',
                      'v1.29.3',
                      'v2.0.4',
                      'v2.7.4',
                      'v1.22.0',
                      'v1.29.0',
                      'v2.0.1',
                      'v2.7.1',
                      'v1.1.0',
                      'v1.8.0',
                      'v2.3.2',
                      'v1.13.3',
                      'v1.0.2',
                      'v1.13.0',
                      'v2.6.0',
                      'v2.9.7',
                      'v2.2.1',
                      'v2.9.4',
                      'v1.3.0',
                      'v1.24.0',
                      'v1.20.1',
                      'v2.9.1',
                      'v1.6.1',
                      'v1.27.1',
                      'v2.5.2',
                      'v2.1.3',
                      'v1.15.0',
                      'v2.10.2',
                      'v2.1.0',
                      'v2.8.0',
                      'v1.11.1',
                      'v2.4.4',
                      'v1.29.7',
                      'v1.5.3',
                      'v1.26.0',
                      'v1.29.4',
                      'v2.7.5',
                      'v1.22.1',
                      'v1.8.4',
                      'v2.4.1',
                      'v1.14.2',
                      'v1.5.0',
                      'semver',
                      'v1.8.1',
                      'v1.29.1',
                      'v2.0.2',
                      'v2.7.2',
                      'v2.3.3',
                      'v1.10.0',
                      'v2.3.0',
                      'v1.17.0',
                      'v1.13.4',
                      'v1.13.1',
                      'v1.0.3',
                      'v1.21.0',
                      'v2.6.1',
                      'v1.0.0',
                      'v1.7.0',
                      'v1.28.0',
                      'v2.9.5',
                      'v1.24.1',
                      'v1.20.2',
                      'v1.12.0',
                      'v2.9.2',
                      'v1.19.0',
                      'v1.27.2' ],

                    expected2 = [ 'v2.10.3',
                      'v2.10.2',
                      'v2.10.1',
                      'v2.10.0',
                      'v2.9.7',
                      'v2.9.6',
                      'v2.9.5',
                      'v2.9.4',
                      'v2.9.3',
                      'v2.9.2',
                      'v2.9.1',
                      'v2.9.0',
                      'v2.8.1',
                      'v2.8.0',
                      'v2.7.5',
                      'v2.7.4',
                      'v2.7.3',
                      'v2.7.2',
                      'v2.7.1',
                      'v2.7.0',
                      'v2.6.1',
                      'v2.6.0',
                      'v2.5.2',
                      'v2.5.1',
                      'v2.5.0',
                      'v2.4.6',
                      'v2.4.5',
                      'v2.4.4',
                      'v2.4.3',
                      'v2.4.2',
                      'v2.4.1',
                      'v2.4.0',
                      'v2.3.4',
                      'v2.3.3',
                      'v2.3.2',
                      'v2.3.1',
                      'v2.3.0',
                      'v2.2.1',
                      'v2.2.0',
                      'v2.1.3',
                      'v2.1.2',
                      'v2.1.1',
                      'v2.1.0',
                      'v2.0.4',
                      'v2.0.3',
                      'v2.0.2',
                      'v2.0.1',
                      'v2.0.0',
                      'v1.29.7',
                      'v1.29.6',
                      'v1.29.5',
                      'v1.29.4',
                      'v1.29.3',
                      'v1.29.2',
                      'v1.29.1',
                      'v1.29.0',
                      'v1.28.1',
                      'v1.28.0',
                      'v1.27.2',
                      'v1.27.1',
                      'v1.27.0',
                      'v1.26.0',
                      'v1.25.0',
                      'v1.24.1',
                      'v1.24.0',
                      'v1.23.0',
                      'v1.22.1',
                      'v1.22.0',
                      'v1.21.0',
                      'v1.20.3',
                      'v1.20.2',
                      'v1.20.1',
                      'v1.20.0',
                      'v1.19.1',
                      'v1.19.0',
                      'v1.18.0',
                      'v1.17.1',
                      'v1.17.0',
                      'v1.16.0',
                      'v1.15.1',
                      'v1.15.0',
                      'v1.14.2',
                      'v1.14.1',
                      'v1.14.0',
                      'v1.13.4',
                      'v1.13.3',
                      'v1.13.2',
                      'v1.13.1',
                      'v1.13.0',
                      'v1.12.0',
                      'v1.11.1',
                      'v1.11.0',
                      'v1.10.1',
                      'v1.10.0',
                      'v1.9.1',
                      'v1.9.0',
                      'v1.8.5',
                      'v1.8.4',
                      'v1.8.3',
                      'v1.8.2',
                      'v1.8.1',
                      'v1.8.0',
                      'v1.7.0',
                      'v1.6.1',
                      'v1.6.0',
                      'v1.5.3',
                      'v1.5.2',
                      'v1.5.1',
                      'v1.5.0',
                      'v1.4.0',
                      'v1.3.0',
                      'v1.2.1',
                      'v1.2.0',
                      'v1.1.0',
                      'v1.0.3',
                      'v1.0.2',
                      'v1.0.1',
                      'v1.0.0',
                      'semver' ],
                    list3 = ['0.9.8.1', '0.9.8.2', '10.0', '10.1',
                             '10.1.1', '10.2', '0.9.8', '10.2.1', '10.2.1.1',
                             '10.2.1.2'],
                    expected3 = ['10.2.1.2', '10.2.1.1', '10.2.1', '10.2',
                               '10.1.1', '10.1', '10.0', '0.9.8.2', '0.9.8.1',
                               '0.9.8'];

                validate(t, expected1, list1.sort(version.compare));
                validate(t, expected2, list2.sort(version.compare));
                validate(t, expected3, list3.sort(version.compare));

            }
        ]
    );
    doh.run();
});

module.exports = {
    start: start,
    end: end
};
